package com.library.common.core.serialize;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.io.IOException;

/**
 * @Package: com.library.common.core.serialize
 * @ClassName: DesensitizeSerialize
 * @Author: Yin
 * @Date: 11:18
 * @Description: 此文件描述信息
 */
@JsonSerialize
public class DesensitizeSerialize extends JsonSerializer<String> {

    @Override
    public void serialize(String s, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if(! s.isEmpty()) {
            jsonGenerator.writeObject(s.charAt(0) + "***" + s.charAt(s.length() - 1));
        }else {
            jsonGenerator.writeObject(s);
        }

    }
}
